﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using AKMII.DMRA.Common;
using AKMII.DMRA.Business.Management;
using AKMII.DMRA.Business.Rule;

namespace AKMII.DMRA.Web
{
    public partial class HistoryReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindYearList();
            }
        }

        protected void BindYearList()
        {
            for (int i = 2009; i <= CurrentPeriod.Year; i++)
            {
                DrpYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
        }
        protected void btnCommit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMDAccount.Text.Trim()))
            {
                return;
            }

            ReportManager reportManager = new ReportManager();

            //int result = reportManager.CheckReport(txtMDAccount.Text.Trim(),
            //        Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(DrpYear.SelectedValue),
            //        Convert.ToInt32(DrpType.SelectedValue));
            //if (result == 0)
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),
            //        "success", "<script type='text/javascript'>alert('Incorrect MD Id or no history reports for this MD.');</script>");
            //    return;
            //}

               
            using (CommonServiceClient client = new CommonServiceClient())
            {
                client.SendHistoryReport(txtMDAccount.Text.Trim(),
                           Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(DrpYear.SelectedValue), Convert.ToInt32(DrpType.SelectedValue));
             
                //if (result == 1)
                //{
                //    client.SendHistoryReport(txtMDAccount.Text.Trim(),
                //        Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(DrpYear.SelectedValue), Convert.ToInt32(DrpType.SelectedValue));
                //}
                //else
                //{
                //    client.SendReport(txtMDAccount.Text.Trim(),
                //        Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(DrpYear.SelectedValue));
                //}
            }
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),
                "success", "<script type='text/javascript'>alert('History reports will be sent to your mailbox after several minutes, please have a check.');</script>");
        }
    }
}
